package top.callback.inf.beautyleaf.common;

import lombok.Data;

/**
 * ID 生成结果
 *
 * @author Pengyu Gan
 * CreateDate 2021/3/24
 */
@Data
public class IDResult {

    /**
     * 缓冲区内没有号码段可用。一个 ID 已经发完，一个还没有加载好 ID。
     */
    public static int NO_SEGMENT_AVAILABLE = -1;

    /**
     * 号码段缓冲区未初始化
     */
    public static int SEGMENT_BUFFER_NOT_INIT = -2;

    /**
     * 标签不存在
     */
    public static int TAG_NOT_EXISTS = -3;

    /**
     * 没有 ID 生成器可用
     */
    public static int NO_GENERATOR_AVAILABLE = -4;

    /**
     * 时钟回拨
     */
    public static int CLOCK_BACK = -5;

    /**
     * 未知异常
     */
    public static int UNKNOWN_EXCEPTION = -6;

    /**
     * ID 获取成功
     */
    public static int OK = 0;

    private boolean success;

    private int code = OK;

    private long id;

    public static IDResult ok(long id) {
        IDResult result = new IDResult();
        result.setSuccess(true);
        result.setId(id);
        return result;
    }

    public static IDResult error(int code) {
        IDResult result = new IDResult();
        result.setSuccess(false);
        result.setCode(code);
        return result;
    }
}
